package com.gxc.controller;

import com.google.common.collect.Maps;
import com.gxc.feign.OrderFeign;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;
import java.util.Date;
import java.util.Map;

/**
 * UserController.
 * @author GongXincheng
 * @since 2019-08-25 01:41
 */
@RestController
public class UserController {

    private static final String ORDER_SERVER_URL = "http://springcloud-order";

    @Resource private OrderFeign orderFeign;
    @Resource private RestTemplate restTemplate;

    @GetMapping("/user")
    public Object getUser() {
        Map<String, Object> user = Maps.newHashMap();
        user.put("username","GongXincheng");
        user.put("age", 23);
        user.put("birthday", new Date());
        return user;
    }

    @GetMapping("/feign/order")
    public Object feignGetOrder() {
        return orderFeign.getOrder();
    }

    @GetMapping("/rest/order")
    public Object restGetOrder() {
        return restTemplate.getForObject(ORDER_SERVER_URL + "/order", Object.class);
    }
}
